package com.zmzncs.lmtc.module.customer.service.impl;

import com.zmzncs.lmtc.common.pojo.daoer.CreateMonth;
import com.zmzncs.lmtc.common.util.DateTimeUtil;
import com.zmzncs.lmtc.module.customer.pojo.month_record.MonthRecord;
import com.zmzncs.lmtc.module.customer.dao.MonthRecordDao;
import com.zmzncs.lmtc.module.customer.pojo.month_record.MonthRecordDTO;
import com.zmzncs.lmtc.module.customer.service.MonthRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 月租车信息表 服务实现类
 * </p>
 *
 * @author 作者
 * @since 2021-02-05
 */
@Service
public class MonthRecordServiceImpl extends ServiceImpl<MonthRecordDao, MonthRecord> implements MonthRecordService {

    @Autowired
    MonthRecordDao monthRecordDao;

    @Override
    public int addMonthRecord(CreateMonth createMonth) {

        MonthRecord monthRecord = new MonthRecord();
        monthRecord.setPayStatus(1);
        monthRecord.setParkInfoId(createMonth.getParkInfoId());
        monthRecord.setCarNumber(createMonth.getCarNo());
        monthRecord.setMobilePhone(createMonth.getConcatPhone());
        Integer cardTypeId = createMonth.getCardTypeId();
        if (cardTypeId != null){
            monthRecord.setMonthType(cardTypeId.toString());
        }
        monthRecord.setParkSource(createMonth.getParkSource());
        String balanceMoney = createMonth.getBalanceMoney();
        BigDecimal amount = new BigDecimal(balanceMoney);
        monthRecord.setAmount(amount);
        String startTime = createMonth.getStartTime();
        if (startTime != null){
            Date beginTime = DateTimeUtil.fomatDateTime(startTime);
            monthRecord.setBeginTime(beginTime);
        }
        String endTime = createMonth.getEndTime();
        if (endTime != null){
            Date end = DateTimeUtil.fomatDateTime(endTime);
            monthRecord.setExpireTime(end);
        }
        monthRecord.setParkManagerId(createMonth.getParkManagerId());
        monthRecord.setCreateTime(new Date());

        return monthRecordDao.insert(monthRecord);
    }

    @Override
    public List<MonthRecord> getRecordByParkIdAndCarNo(Long parkId, String carNumber) {
        return monthRecordDao.getRecordByParkIdAndCarNo(parkId,carNumber);
    }

    @Override
    public String getMonthRecordAmountByDate(Long parkId, Integer dateType) {
        return monthRecordDao.getMonthRecordAmountByDate(parkId, dateType);
    }

    @Override
    public List<MonthRecordDTO> getMonthRecordByStatus(Long parkId, Integer monthStatus) {
        return monthRecordDao.getMonthRecordByStatus(parkId,monthStatus);
    }
}
